import router from '@/router'
import axios from "axios"
import {getShopRoad} from '@/api'
import * as types from '../types'
import {Tools} from "../../lib/tools";
import { Indicator } from 'mint-ui';


const state = {
    popupVisible: false,
    nextBtnDisabled: true,
    ChooseName: "",
    needData: "营业地址路名",
    shopHouse: '营业地址门牌',
    shopRoadValue: '',
    shopHouseValue: '',
    OppName: '',
    placeholder: '请输入营业地址路名（必填）',
    shopHousePlaceholder: '请输入营业地址门牌（必填）',
    areaData: '',
    companyAddress: [
        {name: 'companyAddress', content: '经营地址', all: '请选择经营地址(必填)', choose: ''},
    ],
    industry: [
        {name: 'industry', content: '所属行业', all: '请选择所属行业(选填)', choose: ''},
    ],
    auxiliary: [
        {name: 'auxiliary', content: '辅助证明材料', all: '请上传辅助证明材料(必填)', choose: ''},
    ],
    slotData: [
        {
            flex: 1,
            values: [],
            className: 'slot1',
            textAlign: 'center',
        },
    ],
    auxiliaryPicture:'',
    allAreaList:"",
    areaList:[],
    areaCode:""


}

const getters = {}

const actions = {
    [types.GET_SHOP_ROAD]({state,rootState}) {
        Indicator.open();
        getShopRoad({
            json: {
                "service":'areaQueryForWx',
                "wxRequestDate":(new Date()).format("yyyyMMddhhmmss"),
            }
        }).then(data => {
            console.log(data)
            let DataLIST=JSON.parse(data.areaList).AREADetail
            rootState.companyAddress.allAreaList=DataLIST
            rootState.companyAddress.slotData[0].values=[]
            for (let i =0;i<DataLIST.length;i++){
                (rootState.companyAddress.slotData[0].values).push(DataLIST[i].AREADetail.AREANAME)
            }
            rootState.companyAddress.areaList=rootState.companyAddress.slotData[0].values
        })}
}

const mutations = {
    [types.COMPANYADDRESS_SHOW_SELECT_LIST](state, value) {
        state.OppName = value;
        if (value == 'companyAddress') {
            state.ChooseName = '经营地址';
            state.popupVisible = !state.popupVisible
            console.log(state.areaList)
        } else if (value == 'auxiliary') {
            router.push('auxiliary')

        }
    },
    [types.COMPANYADDRESS_SELECT_CANCLE](state) {
        state.popupVisible = !state.popupVisible
    },
    [types.COMPANYADDRESS_SELECT_CHANGE](state) {
        state.popupVisible = false
    },
    [types.COMPANYADDRESS_GET_INPUT_VALUE](state, value) {
        state.shopRoadValue = value
    },
   [types.GET_SHOP_HOUSE_CHANGE](state, value) {
        state.shopHouseValue = value
    },
    [types.COMPANYADDRESS_NEXT_BUTTON_CHECK](state) {
        if (Tools.check.isEmpty(state.companyAddress[0].choose) ||
            Tools.check.isEmpty(state.shopRoadValue) ||
            Tools.check.isEmpty(state.shopHouseValue) ||
            Tools.check.isEmpty(state.auxiliaryPicture)
        ) {
            state.nextBtnDisabled = true
        } else state.nextBtnDisabled = false
    }
};

export default {
    namespaced: true,
    state,
    actions,
    mutations,
    getters
}